package org.wanghong.gift.exception.asserts;

import org.wanghong.gift.exception.BusinessException;
import org.wanghong.gift.exception.statuCode.StatusCode;

import java.util.List;

//断言类
public class Assert {

    public static void assertListIsEmpty(List<?> list, StatusCode code){
        if (list!=null && list.size()>0)
            throw new BusinessException(code.getCode(),code.getMessage());
    }
    //断言不为空
    public static void assertNotNull(Object obj,String message){
        if (obj==null)
            throw new BusinessException(message);
    }
    //断言不为空串
    public static void assertNotEmpty(String string,String message){
        if(string==null || string.trim().equals(""))
        throw  new BusinessException(message);
    }
    //断言
    public static void assertNotEmpty(String str,StatusCode code){
        if (str==null || str.trim().equals(""))
            throw new BusinessException(code.getCode(),code.getMessage());
    }
    //断言List为null
    public static void assertListIsEmpty(List<?> list,String message){
        if(list!=null && list.size()>0)
            throw  new BusinessException(message);
    }


    //断言相等
    public static void assertEquals(String str1,String str2,String message){
        if(!str1.trim().equals(str2.trim()))
            throw  new BusinessException(message);
    }
    //断言不相等
    public static void assertNotEquals(String str1,String str2,String message){
        if(str1.trim().equals(str2.trim()))
            throw  new BusinessException(message);
    }
    public static void assertEqualsIgnoreCase(String str1,String str2,StatusCode code){

        if (!str1.trim().equalsIgnoreCase(str2.trim()))
            throw new BusinessException(code.getCode(),code.getMessage());
    }

    public static void assertEqualsIgnoreCase(String str1,String str2,String message){

        if (!str1.trim().equalsIgnoreCase(str2.trim()))
            throw new BusinessException(message);
    }
    public static void assertListNotEmpty(List<?> list, StatusCode code){
        if (list==null || list.size()<1)
            throw new BusinessException(code.getCode(),code.getMessage());
    }




}
